package com.xc.otc

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.ViewGroup
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.get
import com.fker.opt.AESUtils
import com.fker.opt.JNIFKerLibs

class MainActivity : AppCompatActivity() {
    @SuppressLint("ClickableViewAccessibility")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val rlBg = findViewById<RelativeLayout>(R.id.rl_bg)
        val tvHello = findViewById<TextView>(R.id.tv_hello)
        val clLayout = findViewById<ConstraintLayout>(R.id.cl_layout)

        val tvDialog = findViewById<TextView>(R.id.tv_dialog)


        tvDialog.setOnClickListener {
            AdDialog.show(this)
        }


        rlBg.setOnClickListener {
            Log.i("chyy", "rlbg: Click ")

            Log.i("opt-core", "demo packageName: " + AESUtils.encrypt(packageName))

            val encrypt = AESUtils.encrypt("com.yuezhong.drama")
            Log.i("opt-core", encrypt)


            Log.i("opt-core  jimi: ", AESUtils.decrypt(encrypt))

            printAdLayout(clLayout)
        }

        tvHello.setOnClickListener {
            it.postDelayed({
                JNIFKerLibs.send(rlBg, 100, 100)
            }, 2000)

        }

        rlBg.setOnTouchListener { v, event ->
            when (event.action) {
                MotionEvent.ACTION_UP -> {
                    Log.i("chyy", "rlbg: Click Listener ")
                }
            }
            false
        }


    }

    private fun printAdLayout(viewGroup: ViewGroup) {
        val childCount = viewGroup.childCount
        Log.i("chyy", "" + viewGroup.toString());
        for (i in 0 until childCount) {
            val view = viewGroup[i]
            Log.i("chyy", "" + view.toString());
            if (view is ViewGroup && view.childCount > 0) {
                printAdLayout(viewGroup)
            }

        }
    }
}